/*
 * OpenButton.java
 *
 * Copyright 2007, 2008 Tiberiumlabs
 *
 * This file is part of Tiberiumlabs Lailaps.
 *
 * Tiberiumlabs Lailaps is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 3 of the License, or
 * (at your option) any later version.
 *
 * Tiberiumlabs Lailaps is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
package org.tiberiumlabs.lailaps.gui.elements;

import java.awt.Insets;
import javax.swing.Action;
import javax.swing.Icon;
import javax.swing.JButton;
import org.tiberiumlabs.lailaps.resources.ImageLoader;

/**
 * Small button with folder icon, containing empty text and can be easyly used by GUI Builders.
 * Optimized for 17x17 icon.
 *
 * @author <a href="paranoid.tiberiumlabs@gmail.com">Paranoid</a>
 */
public class OpenButton extends JButton {

    private static final String TEXT = " ";
    private static final Insets INSETS = new Insets(0, 3, 0, 0);

    public OpenButton() {
        super(ImageLoader.getOpenImageSmall());
        init();
    }

    public OpenButton(Action action) {
        super(action);
        setIcon(ImageLoader.getOpenImageSmall());
        init();
        //super(action, ImageLoader.getOpenImageSmall());
    }

    private void init() {
        setText(TEXT);
        setIconTextGap(0);
        setMargin(INSETS);
        setMaximumSize(getPreferredSize());
    }

    /**
     * Sets the button's default icon. This icon is
     * also used as the "pressed" and "disabled" icon if
     * there is no explicitly set pressed icon.
     *
     * @param icon the icon used as the default image
     */
    public void setImage(Icon icon) {
        setIcon(icon);
    }

}
